﻿using System;
using System.Linq;
namespace LinqExer
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int[] numbers = new int[100];
            Random rd = new Random();
            for(int i = 0; i < 100; i++)
            {
                numbers[i] = rd.Next(1001);//生成0到1000之间的随机数
            }

            //使用LINQ语句对这些整数从大到小排序，并求和与平均数。
            var sortedNumbers = from n in numbers orderby n descending select n;
            foreach(var x in sortedNumbers)
            {
                Console.WriteLine(x);
            }
            int sum = sortedNumbers.Sum();
            Console.WriteLine("和为：" + sum);
            double average = sortedNumbers.Average();
            Console.WriteLine("平均数为：" + average);
        }
    }
}
